<template>
  <div>
    <a-input v-model="username" placeholder="请输入激活码"></a-input>

    <a-button type="primary" @click="handleButtonClick">发送请求</a-button>

    <a-upload :before-upload="handleFileUpload" :show-upload-list="false">
      <a-button type="primary">请上传知识库</a-button>
    </a-upload>

    <a-button type="primary">读取历史数据</a-button>

    <div class="table-title">以下是上传的知识库内容</div>

    <a-table :columns="columns" :data-source="data"></a-table>

  </div>
</template>
  
<script>
import { ref } from 'vue';
import { message } from 'ant-design-vue';
import axios from 'axios';
import myAxios from '@/utils/myAxios';

export default {
  name: 'UploadForm',
  setup() {
    const username = ref('');

    // 处理按钮点击事件
    const handleButtonClick = async () => {
      // 发起HTTP请求
      myAxios.get('/home/getData')
        .then((response) => {
          // 处理请求成功的响应数据
          console.log(response);
          message.success('请求成功');
        })
        .catch((error) => {
          // 处理请求失败的错误
          console.error(error);
          message.error('请求失败');
        });
    };

    const handleFileUpload = async (file) => {
      try {
        const formData = new FormData();
        formData.append('file', file);
        formData.append('username', username.value);

        await axios.post('http://your-python-api-url', formData, {
          headers: {
            'Content-Type': 'multipart/form-data',
          },
        });
        // 在这里处理响应结果
        message.success('上传成功');
      } catch (error) {
        console.error(error);
        message.error('上传失败');
      }
    };

    return {
      username,
      handleFileUpload,
      handleButtonClick
    };
  },
};
</script>
  
<style>
/* 可以根据需要添加样式 */
</style>